{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "\n",
       "require(['notebook/js/codecell'], function(codecell) {\n",
       "  codecell.CodeCell.options_default.highlight_modes[\n",
       "      'magic_text/x-csrc'] = {'reg':[/^%%microblaze/]};\n",
       "  Jupyter.notebook.events.one('kernel_ready.Kernel', function(){\n",
       "      Jupyter.notebook.get_cells().map(function(cell){\n",
       "          if (cell.cell_type == 'code'){ cell.auto_highlight(); } }) ;\n",
       "  });\n",
       "});\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from pynq import Overlay\n",
    "\n",
    "overlay = Overlay('./prm.bit')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#overlay?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "prm = overlay.prm_chk_v1_0_0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "selectEdge_Wire0 = 0*4\n",
    "selectEdge_Wire1 = 1*4\n",
    "selectEdge_Wire2 = 2*4\n",
    "selectEdge_Wire3 = 3*4\n",
    "selectEdge_Wire4 = 4*4\n",
    "selectEdge_Wire5 = 5*4\n",
    "selectEdge_Wire6 = 6*4\n",
    "selectEdge_Wire7 = 7*4\n",
    "selectEdge_Wire8 = 8*4\n",
    "selectEdge_Wire9 = 9*4\n",
    "\n",
    "edgeMask_Wire0 = 10*4\n",
    "edgeMask_Wire1 = 11*4\n",
    "edgeMask_Wire2 = 12*4\n",
    "edgeMask_Wire3 = 13*4\n",
    "edgeMask_Wire4 = 14*4\n",
    "edgeMask_Wire5 = 15*4\n",
    "edgeMask_Wire6 = 16*4\n",
    "edgeMask_Wire7 = 17*4\n",
    "edgeMask_Wire8 = 18*4\n",
    "edgeMask_Wire9 = 19*4\n",
    "edgeMask_Wire10 = 20*4\n",
    "edgeMask_Wire11 = 21*4\n",
    "edgeMask_Wire12 = 22*4\n",
    "edgeMask_Wire13 = 23*4\n",
    "edgeMask_Wire14 = 24*4\n",
    "edgeMask_Wire15 = 25*4\n",
    "edgeMask_Wire16 = 26*4\n",
    "edgeMask_Wire17 = 27*4\n",
    "edgeMask_Wire18 = 28*4\n",
    "edgeMask_Wire19 = 29*4\n",
    "edgeMask_Wire20 = 30*4\n",
    "edgeMask_Wire21 = 31*4\n",
    "edgeMask_Wire22 = 32*4\n",
    "edgeMask_Wire23 = 33*4\n",
    "edgeMask_Wire24 = 34*4\n",
    "edgeMask_Wire25 = 35*4\n",
    "edgeMask_Wire26 = 36*4\n",
    "edgeMask_Wire27 = 37*4\n",
    "edgeMask_Wire28 = 38*4\n",
    "edgeMask_Wire29 = 39*4\n",
    "edgeMask_Wire30 = 40*4\n",
    "edgeMask_Wire31 = 41*4\n",
    "edgeMask_Wire32 = 42*4\n",
    "stateMonitor = 43*4\n",
    "\n",
    "endPoseReg = 46*4\n",
    "startPoseReg = 47*4\n",
    "obstaleIndexReg = 48*4\n",
    "controlReg = 49*4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "#reset\n",
    "prm.write(controlReg,0x01 )\n",
    "prm.write(controlReg,0x00 )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "#create obstacle and write into PL\n",
    "for X in range(0,12):\n",
    "    for Y in range(0,15):\n",
    "        for Z in range(0,20):\n",
    "            obIndex = X*1024 + Y*32 + Z\n",
    "            prm.write(obstaleIndexReg,obIndex )\n",
    "for X in range(0,12):\n",
    "    for Y in range(27,32):\n",
    "        for Z in range(28,32):\n",
    "            obIndex = X*1024 + Y*32 + Z\n",
    "            prm.write(obstaleIndexReg,obIndex )\n",
    "\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n"
     ]
    }
   ],
   "source": [
    "print (prm.read(stateMonitor))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0b111111000100111111011100110000\n",
      "0b1010000100000001111111000101010\n",
      "0b100100111111111110111111110101\n",
      "0b1010011111111111111101011000111\n",
      "0b1110111000100010010010000001010\n",
      "0b11110001101001010011010000011000\n",
      "0b11111111111111111111111111111111\n",
      "0b100101101011000000100000001111\n",
      "0b10000000000000001001000000110001\n",
      "0b11111111100011000100111011101010\n",
      "0b11111111111111111111111111111111\n",
      "0b11111111111111111111111111111111\n",
      "0b10010100110000011011111111111111\n",
      "0b100100100100101000000000100000\n",
      "0b11010000110000000000011000001100\n",
      "0b1110000110000100100100100\n",
      "0b11111111111111111111111100000000\n",
      "0b100001000001001001000111111111\n",
      "0b1100000100010010000001000110\n",
      "0b10110000100011000000001010100110\n",
      "0b11111111111110100011110000001001\n",
      "0b11001001000000111111111111111111\n",
      "0b10000000000001010011011010\n",
      "0b11111111111111111111111111111111\n",
      "0b11111111111111111111111111111111\n",
      "0b1111111111111111111111111111111\n",
      "0b10000001000010000000000000000000\n",
      "0b10010010110100000000000000000000\n",
      "0b100011101110100111111110111011\n",
      "0b11111110010000010000000010001001\n",
      "0b111111111111111111111111111\n",
      "0b1011010000011001010000000000010\n",
      "0b1111101011\n"
     ]
    }
   ],
   "source": [
    "#no connection for obstacle checking\n",
    "for i in range(10,43):\n",
    "    print(bin(prm.read(i*4)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    }
   ],
   "source": [
    "#load start pose and end pose and forword init\n",
    "prm.write(startPoseReg,0)\n",
    "prm.write(endPoseReg,60)\n",
    "prm.write(controlReg,0x2)\n",
    "print (prm.read(stateMonitor))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0b1111111101111111111111101110011\n",
      "0b11111101111101001111111000101011\n",
      "0b11111101111111111110111111111111\n",
      "0b11110011111111111111101111000111\n",
      "0b11110111111111111111011111011111\n",
      "0b11111111111111111111111011111101\n",
      "0b11111111111111111111111111111111\n",
      "0b11111111111111101111111111011111\n",
      "0b11111111101111111111111010111111\n",
      "0b11111111111111111111111111111110\n",
      "0b11111111111111111111111111111111\n",
      "0b11111111111111111111111111111111\n",
      "0b11111100111111011111111111111111\n",
      "0b11111111111111101111111111111111\n",
      "0b11111011111111110101111111111111\n",
      "0b11101111111111111111111111111111\n",
      "0b11111111111111111111111111111111\n",
      "0b11111111111111111111100111111111\n",
      "0b11111111111111111111111011110111\n",
      "0b11110111111111111111111111110111\n",
      "0b11111111111111111111111111111111\n",
      "0b11111111111100111111111111111111\n",
      "0b11111111111111111011111011111111\n",
      "0b11111111111111111111111111111111\n",
      "0b11111111111111111111111111111111\n",
      "0b1111111111111111111111111111111\n",
      "0b11111001111111111111111111111110\n",
      "0b11111111111111111111111111111111\n",
      "0b11111111111111111111111111111111\n",
      "0b11111111111111111111111111111111\n",
      "0b11111111111111111111111111111111\n",
      "0b11111111111111111111111111111111\n",
      "0b1111111111\n"
     ]
    }
   ],
   "source": [
    "for i in range(10,43):\n",
    "    print(bin(prm.read(i*4)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "prm.write(controlReg,0x4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "858\n",
      "3\n",
      "2\n",
      "0\n",
      "0\n",
      "0\n",
      "0\n",
      "0\n",
      "0\n",
      "0\n"
     ]
    }
   ],
   "source": [
    "for i in range(0,10):\n",
    "    print(prm.read(i*4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n"
     ]
    }
   ],
   "source": [
    "print (prm.read(stateMonitor))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
